package com.googlecode.tinyjava.syntaxtree;

import com.googlecode.tinyjava.symboltable.NamedItem;

public class BlockStatement extends Statement {

	private TreeNode head;
	private TreeNode tail;

	public BlockStatement(NamedItem item) {
		super(item);
	}

	public BlockStatement() {
		super(null);
	}

	public void add(TreeNode stmt) {
		if (head == null) {
			head = stmt;
		} else {
			tail.setNext(stmt);
		}
		tail = stmt;
	}
	
	public void print() {
		if (this instanceof PackageStatement)
			System.out.println(this.getReference() + ";");
		else
			System.out.println(this.getReference() + " {");
		TreeNode curr = head;
		while (curr != null) {
			curr.print();
			curr = curr.getNext();
		}
		System.out.println("}");
	}
}
